package com.mankind.ssm.service;

import com.mankind.ssm.common.CONSTANT;
import com.mankind.ssm.common.Page;
import com.mankind.ssm.mapper.UserInfoMapper;
import com.mankind.ssm.pojo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Mankind on 2017/7/14.
 */
@Service("userInfoService")
public class UserInfoServiceImpl implements UserInfoService {
    @Autowired
    private UserInfoMapper userInfoMapper;
    public Page<UserInfo> getUserInfoByPage(int pageSize,int currentPage){
        Page<UserInfo> p=new Page<UserInfo>();
        int start=(currentPage-1)*pageSize;
        List<UserInfo> u=userInfoMapper.findByPage(start,pageSize);
        p.setNumberPage(pageSize);
        p.setObj(u);
        return p;
    }
    public Integer getTotalNumber(){
        Integer num=userInfoMapper.getTotalNumber();
        if(num==0) return 0;
        return (num-1)/ CONSTANT.USERINFO_LIST_SIZE+1;
    }
    public Integer getTotalNumber(String text){
        int num=userInfoMapper.getFuzzyQueryTotalNumber(text);
        System.out.println("num:"+num);
        if(num==0) return 0;
        return (num-1)/ CONSTANT.USERINFO_LIST_SIZE+1;
    }
    public void update(UserInfo userInfo){
        userInfoMapper.updateByPrimaryKey(userInfo);
    }
    public UserInfo getUserInfoById(Integer id){
        return userInfoMapper.selectByPrimaryKey(id);
    }
    public Page<UserInfo> fuzzyQueryByPage(int currentPage,int pageSize,String text){
        Page<UserInfo> p=new Page<UserInfo>();
        int start=(currentPage-1)*pageSize;
        List<UserInfo> u=userInfoMapper.fuzzyQueryByPage(start,pageSize,text);
        p.setNumberPage(pageSize);
        p.setObj(u);
        return p;
    }
}
